import BaseShape2D from "./BaseShape2D";
import Vector2 from "../maths/Vector2";
import ITransformable from "../interfaces/ITransformable";
import IRenderState from "../interfaces/IRenderState";
import Math2D from "../maths/Math2D";

export default class Ellipse extends BaseShape2D {
    public radiusX: number;
    public radiusY: number;
    // 椭圆圆心在局部坐标系的[ 0 , 0 ]位置处

    public get type(): string {
        return "Ellipse";
    }

    public constructor(radiusX: number = 10, radiusY: number = 10) {
        super();
        this.radiusX = radiusX;
        this.radiusY = radiusY;
    }

    // 调用Math2D类的isPointInCircle静态方法
    public hitTest(localPt: Vector2, transform: ITransformable): boolean {
        let isHitted: boolean = Math2D.isPointInEllipse(localPt.x, localPt.y, 0, 0, this.radiusX, this.radiusY);
        return isHitted;
    }
    public draw(transformable: ITransformable, state: IRenderState,
        context: CanvasRenderingContext2D): void {
        context.beginPath();
        context.beginPath();
        context.ellipse(0, 0, this.radiusX, this.radiusY, 0, 0, Math.PI * 2);
        //必须放在最后，调用绘制命令
        super.draw(transformable, state, context);
    }
}